package com.sip.db.service.impl;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.sip.db.dao.ChannelRepository;
import com.sip.db.entity.ChannelEntity;
import com.sip.db.service.ChannelService;

@Service
public class ChannelServiceImpl implements ChannelService {
	@Autowired
	ChannelRepository channelRepository;
	
	@Override
	public ChannelEntity saveOrUpdate(ChannelEntity channelEntity) {
		return channelRepository.save(channelEntity);
	}

	@Override
	public ChannelEntity findOne(ChannelEntity channelEntity) {
		Example<ChannelEntity> example = Example.of(channelEntity);
		Optional<ChannelEntity> optional = channelRepository.findOne(example);
		if (optional.isPresent()) {
			ChannelEntity device = optional.get();
			return device;
		} else {
			return null;
		}
	}

	@Override
	public List<ChannelEntity> listAll(ChannelEntity channelEntity) {
		Example<ChannelEntity> example = Example.of(channelEntity);
		List<ChannelEntity> deviceList = channelRepository.findAll(example);
		return deviceList;
	}

	@Override
	public void delete(ChannelEntity channelEntity) {
		channelRepository.delete(channelEntity);
	}

}
